﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;

namespace com.lover.astd.common.logicexe.temp
{
    public class CreditWashExe : TempExeBase, ITempExe
    {
        public CreditWashExe() { _name = ConfigStrings.S_Temp; _readable = ConfigStrings.SR_Temp; }
        private bool _finished = false;
        private int _wash_id = 0;
        private string _wash_what = "";
        private int[] _now_attrib = new int[3] { 0, 0, 0 };
        public override long execute()
        {
            HeroMgr mgr = ServiceFactory.getHeroManager();
            if (_wash_id == 0 || _wash_what == "")
            {
                logInfo("没有可洗的武将");
                return next_hour();
            }

            int wash_result = mgr.startWash(_proto, _logger, _user, _wash_id, _wash_what, false, getCreditAvailable(), 20, ref _now_attrib);
            if (wash_result == 1) { _finished = true; }
            else if (wash_result == 2) { _finished = false; return next_halfhour(); }
            else if (wash_result == 3) { _finished = false; return next_day(); }
            return immediate();
        }
        #region ITempExe 成员

        public bool isFinished()
        {
            return _finished;
        }

        public void setTarget(Dictionary<string, string> conf)
        {
            if (conf == null || !conf.ContainsKey("wash_id")) return;
            if (conf == null || !conf.ContainsKey("wash_what")) return;
            Int32.TryParse(conf["wash_id"], out _wash_id);
            _wash_what = conf["wash_what"];
        }

        public string getStatus()
        {
            if (!_finished) return String.Format("进行中,统{0},勇{1},智{2}", _now_attrib[0], _now_attrib[1], _now_attrib[2]);
            else return "完成";
        }

        #endregion
    }
}
